<?php

// ##############################################################################||
// #                                                                 
// #   MySmartBB Version 1.7.0	                                      
// #   http://www.MySmartBB.com                                      
// #   Copyright (c) 2008 by MySmartBB team                           
// #   license http://opensource.org/licenses/gpl-license.php GNU Public License
// #                                                             
// #   filename : new .php                                          
// #   show pages which don't need header template            
// #                                                                  
// ##############################################################################||

// ** General definitions **

     define('NOT_IN_INDEX',0);
     define('NO_HEADER',1);
     include('common.php');

     if ($_GET['smile'] == 1)
     {
         $SF->html_title_page('الابتسامات - (Powered By MySmartBB Universal)');

         $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC");

         $smiles_row = array();
         while ($smile_row = $DB->sql_fetch_array($smiles_query))
         {
             $smiles_row[] = $smile_row;
             $Smarty->assign('smiles_row',$smiles_row);
         }

         $Smarty->display('all-smiles.tpl');
     }
     
	 	     elseif ($_GET['users'] == 1)
    {
            $id = intval($_GET['id']);
            $replys = $DB->sql_query("SELECT writer FROM " . $db_prefix . "reply WHERE subject_id = '" . $id . "' AND delete_topic != '1' ORDER BY id ASC");
            $Count_replys = $DB->sql_num_rows($replys);
            $Smarty->assign('count_reply',$Count_replys);
            $replys2 = $DB->sql_query("SELECT DISTINCT writer FROM " . $db_prefix . "reply WHERE subject_id = '" . $id . "' AND delete_topic != '1' ORDER BY id ASC");

            $users_row = array();
            $replys_user_count = array();

              while ($users = $DB->sql_fetch_array($replys2)){
                      $replys_user_count[] = $DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id = '" . $id . "' AND delete_topic != '1' AND writer = '" . $users['writer'] . "' ORDER BY id ASC"));
                      $users_row[] = $users;
                      $Smarty->assign('users_row',$users_row);
                      $Smarty->assign('replys_user_count',$replys_user_count);
              }
            $Smarty->assign('subjedt_id',$id);
			$Smarty->display('section_members-replies.tpl');
    }
	
	elseif ($_GET['print'] == 1)
	{
		$id = intval($_GET['id']);

		$thread_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . $id . "'");
		$thread_num = $DB->sql_num_rows($thread_query);
		if ($thread_num < 1 )
		{
			$SF->error('المعذرة الموضوع المطلوب غير الموجود',1);
		}
		else
		{
			$thread_row = $DB->sql_fetch_array($thread_query);
			if ($thread_row['delete_topic'] == 1 and $groupper_row['admincp_allow'] != 1)
			{
				$SF->error('هذا الموضوع منقول لسلة المحذوفات',1);
			}

			if ($member_permission != 0)
			{
				$group_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "sectiongroup WHERE group_id='" . $member_row['usergroup'] . "' AND section_id='" . $thread_row['section'] . "'");
				$group_row = $DB->sql_fetch_array($group_query);
			}
			else
			{
				$group_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "sectiongroup WHERE group_id='7' AND section_id='" . $thread_row['section'] . "'");
				$group_row = $DB->sql_fetch_array($group_query);
			}

			if ($group_row['view_section'] == 1)
			{
				$section_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $thread_row['section'] . "'");
				$section_row = $DB->sql_fetch_array($section_query);

				$SF->html_title_page($thread_row['title'] . ' - (Powered By MySmartBB Universal)');

				$text = $thread_row['text'];
				$text = str_replace('>', '>', $text);
				$text = str_replace('<', '<', $text);
				$text = $SF->SmartCode_replace($text);

				$Smarty->assign_by_ref('thread_row',$thread_row);
				$Smarty->assign('text',$text);
				$Smarty->assign('section_title',$section_row['title']);
				$Smarty->display('post_print-subject.tpl');
			}
			else
			{
				$SF->html_title_page($thread_row['title'] . ' - (Powered By MySmartBB Universal)');
				$SF->msg('المعذرة , لايُمكنك الإطلاع على الموضوع');
			}

		}
	}

     elseif ($_GET['friend'] == 1)
     {
         if ($_GET['index'] == 1)
         {
             $id = intval($_GET['id']);

             $subject_query = $DB->sql_query("SELECT
                                              " . $db_prefix . "subject.id AS id,
                                              " . $db_prefix . "subject.title AS title,
                                              " . $db_prefix . "subject.section AS section,
                                              " . $db_prefix . "section.id AS section_id
                                              FROM " . $db_prefix . "subject AS " . $db_prefix . "subject, " . $db_prefix . "section AS " . $db_prefix . "section
                                              WHERE " . $db_prefix . "subject.id = '$id'");

             $subject_num   = $DB->sql_num_rows($subject_query);
             $subject_row   = $DB->sql_fetch_array($subject_query);

             if ($subject_num == 0)
             {
                 $SF->msg('المعذرة، الموضوع المطلوب غير موجود');
             }

             if ($subject_row['delete_topic'] == 1 and $groupper_row['admincp_allow'] != 1)
             {
                 $SF->msg('هذا الموضوع منقول لسلّة المحذوفات');
             }

             if ($member_permission != 0)
             {
                 $group_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "sectiongroup WHERE group_id='" . $member_row['usergroup'] . "' AND section_id='" . $subject_row['section_id'] . "'");
                 $group_row   = $DB->sql_fetch_array($group_query);
             }

             if ($member_permission == 0)
             {
                 $group_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "sectiongroup WHERE group_id='7' AND section_id='" . $subject_row['section_id'] . "'");
                 $group_row   = $DB->sql_fetch_array($group_query);
             }

             if ($group_row['view_section'] == 0)
             {
                 $SF->msg('المعذرة، لا يمكنك الاطلاع على هذا الموضوع');
             }

             $Smarty->assign_by_ref('subject_row',$subject_row);

             $SF->html_title_page('إرسال ' . $subject_row['title'] . ' - (Powered By MySmartBB Universal)');

             $url  = "http://{$HTTP_HOST}{$REQUEST_URI}";
             $url  = str_replace('new.php?friend=1&index=1&id=' . $id,'',$url);
             $url .= 'show.php?main=1&id=' . $id;

             $Smarty->assign('url',$url);
             $Smarty->display('post_send-subject.tpl');
         }
         elseif ($_GET['start'] == 1)
         {
             $email_check   = explode('@',$_POST['T1']);

             if (empty($_POST['T1']) or empty($_POST['S1']))
             {
                 $SF->msg('يرجى تعبئة كافة المعلومات');
             }

             if (count($email_check) == 1)
             {
                 $SF->msg('يرجى كتابة البريد الصحيح');
             }

             if ($member_permission == 0)
             {
                 $SF->msg('المعذرة، لا يمكن للزوار إرسال المواضيع');
             }

             $text = nl2br($_POST['S1']);
             $send = $SF->mail($_POST['T1'],'دعوة من صديقك ' . $_COOKIE['MySBB_username'],$text,$member_row['email']);

             if ($send)
             {
                 $SF->msg('أُرسِلَت الرساله بنجاح');
             }
         }
     }

?>